import org.junit.jupiter.api.Test;

/*
 * @description 静态类单例模式
 * @author 罗添煦
 * @create 2024-08-20 下午2:51
 */
public class Singleton_00 {
    // 私有构造函数，防止外部通过new创建实例
    private Singleton_00() {}

    // 静态内部类，含有单一实例
    private static class SingletonHolder {
        private static final Singleton_00 INSTANCE = new Singleton_00();
    }

    // 公有静态方法，返回唯一的实例
    public static Singleton_00 getInstance() {
        return SingletonHolder.INSTANCE;
    }

    @Test
    public void test() {
        Singleton_00 instance1 = Singleton_00.getInstance();
        Singleton_00 instance2 = Singleton_00.getInstance();
        System.out.println(instance1 == instance2);
    }
}


